package com.SpringCloud.user.sso;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.sign.template.SaSignUtil;
import cn.dev33.satoken.sso.processor.SaSsoServerProcessor;
import cn.dev33.satoken.sso.template.SaSsoServerTemplate;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
import cn.dev33.satoken.util.SaFoxUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class SsoServerController {
	@RequestMapping("/sso/*")
	public Object ssoRequest() {
		return SaSsoServerProcessor.instance.dister();
	}

	// 配置SSO相关参数
	@Autowired
	private void configSso(SaSsoServerTemplate ssoServerTemplate) {
		// 配置：未登录时返回的View
		ssoServerTemplate.strategy.notLoginView = () -> {
			String client = SaHolder.getRequest().getParam("client");
            System.out.println("client = " + client);
			return new ModelAndView("login.html");
		};
	}
	@PostMapping("/sso/doLogin")
	public SaResult doLogin(String name, String pwd){
		System.out.println("=======请求进入了自定义的API接口========");
		System.out.println("用户名--" + name + "....密码---" + pwd);
		if ("1".equals(name) && "1".equals(pwd)) {
			StpUtil.login(25);
			return SaResult.ok("登录成功").setData(StpUtil.getTokenValue());
		}
		return SaResult.error("登录失败");
	}

}
